﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class tindiaocban : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TinDiaOcBan();
    }
    public void TinDiaOcBan()
    {
        String sql;
        ConnectionData sqlconn = new ConnectionData();
        sql = "select dt.Id, dt.tieu_de, dt.Ngay_Bat_Dau, dc.So_Nha, dc.Duong_Pho, p.Phuong_Xa, q.Quan_Huyen, tp.Ten_TP,dt.Thuong_Luong, do.Hinh_Anh, do.So_Lau, do.So_Phong_ngu, do.so_phong_khach, do.so_phong_tam, do.so_phong_tam, do.so_phong_khac, do.DTKV, do.DTSD, do.So_Lan_Xem, do.Gia  from DANG_TIN as dt, DIA_OC as do, DIA_CHI as dc, QUAN_HUYEN as q, PHUONG_XA as p, THANH_PHO as tp where dt.Dia_Oc_ID = do.Id and dc.TP_Id = tp.Id and q.TP_Id = tp.Id and p.Quan_id = q.Id and dc.Quan_Id = q.Id and dc.Phuong_id = p.Id and do.Dia_Chi_ID = dc.Id  and dt.Loai_Tin_ID = 3 or dt.Loai_Tin_ID = 4 order by dt.id desc";

        DataSet ds = new DataSet();
        ds = sqlconn.ExecuteQuery(sql);
        dtltindiaocban.DataSource = ds;
        dtltindiaocban.DataBind();
    }

    protected void dtlTintucDiaoc_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        //tin moi nhat
        Image img = default(Image);
        img = (Image)e.Item.FindControl("imgHinh");
        img.ImageUrl = "~/HinhDiaOc/" + Convert.ToString(((DataRowView)e.Item.DataItem)["Hinh_Anh"]);

        //vi tri

        Label vitri = default(Label);
        vitri = (Label)e.Item.FindControl("lblVitri");
        String SoNha = Convert.ToString(((DataRowView)e.Item.DataItem)["so_nha"]);
        String Duong = Convert.ToString(((DataRowView)e.Item.DataItem)["duong_pho"]);
        String Phuong = Convert.ToString(((DataRowView)e.Item.DataItem)["phuong_xa"]);
        String Quan = Convert.ToString(((DataRowView)e.Item.DataItem)["quan_huyen"]);
        String TP = Convert.ToString(((DataRowView)e.Item.DataItem)["ten_tp"]);
        vitri.Text = SoNha + " - " + Duong + " - " + Phuong + " - " + Quan + " - " + TP;

        //tieu de tin dang
        HyperLink tieude = default(HyperLink);
        tieude = (HyperLink)e.Item.FindControl("hpltieude");
        tieude.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Tieu_de"]);
        tieude.NavigateUrl = "~/Chitietdiaoc.aspx?id=" + Convert.ToString(((DataRowView)e.Item.DataItem)["Id"]);

        //ngay dang
        Label ngaydang = default(Label);
        ngaydang = (Label)e.Item.FindControl("lblNgayDang");
        ngaydang.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["ngay_bat_dau"]);

        //DTKV
        Label DTKV = default(Label);
        DTKV = (Label)e.Item.FindControl("lblDTKV");
        DTKV.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["DTKV"]);

        //DTSD
        Label DTSD = default(Label);
        DTSD = (Label)e.Item.FindControl("lblDTSD");
        DTSD.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["DTSD"]);

        //Cau Truc
        Label CauTruc = default(Label);
        CauTruc = (Label)e.Item.FindControl("lblCauTruc");
        String Lau = Convert.ToString(((DataRowView)e.Item.DataItem)["so_lau"]);
        String PhongKhach = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_khach"]);
        String PhongNgu = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_ngu"]);
        String PhongTam = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_tam"]);
        String PhongKhac = Convert.ToString(((DataRowView)e.Item.DataItem)["so_phong_khac"]);
        if (Lau != "")
            CauTruc.Text = Lau + " lầu - ";
        if (PhongKhach != "")
            CauTruc.Text = CauTruc.Text + PhongKhach + " phòng khách - ";
        if (PhongNgu != "")
            CauTruc.Text = CauTruc.Text + PhongNgu + " phòng ngủ - ";
        if (PhongTam != "")
            CauTruc.Text = CauTruc.Text + PhongTam + " phòng tắm/vệ sinh - ";
        if (PhongKhac != "")
            CauTruc.Text = CauTruc.Text + PhongKhac + " phòng khác";

        //Gia
        Label Gia = default(Label);
        Gia = (Label)e.Item.FindControl("lblGia");
        Gia.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Gia"]);

        //Thuong luong
        Label ThuongLuong = default(Label);
        ThuongLuong = (Label)e.Item.FindControl("lblThuongLuong");
        ThuongLuong.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Thuong_Luong"]);

        //So lan xem
        Label LuotXem = default(Label);
        LuotXem = (Label)e.Item.FindControl("lblLanXem");
        LuotXem.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["So_Lan_Xem"]);

        //ket thuc tin moi nhat
    }

    protected void dtltindiaocban_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        dtlTintucDiaoc_ItemDataBound(sender, e);
    }
}